home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
pascal2
/
pro20
/
calendar.p
< prev
next >
Wrap
Text File
|
1986-01-04
|
3KB
|
109 lines
{Include File Calender.P}
{From PCTJ, Dec 85, p.142}
{michael Covington}
{ long range calendrical package in standard pascal }
{ Copyright 1985 Micheal A. Covington }
(*
function Frac(x:real):real
{fractional part of a whole number }
{Turbo pascal provides this as a built-in function}
begin
while x < maxint do x := x + maxint;
while x > do x := x - maxint;
frac := x - trunc(x)
end;
*)
(*
function int(x:real):real;
{ integer part of a real number. }
{ uses real data type to accomodate large numbers }
{ Turbo Pascal provides this as a built in function }
begin
int := x - frac(x)
end;
*)
function floor(x:real):real;
{largest whole number not greater than x}
{uses real data type to accomodate large numbers}
begin
if (x<0) and (frac(x) <> 0) then
floor := int(x) - 1.0
else
floor := int(x)
end;
function daynumber(year, month, day: integer):real;
{ number of days elapsed since 1980 January 0 (1979 December 31). }
{ Note that the year should be given as 1985, not just 85. }
{ Switches from Julian to Geregorian calendar on Oct 15, 1582. }
var
y,m: integer;
a,b,d : real;
begin
if year < 0 then y := year + 1
else y := year;
m := month;
if month < 3 then
begin
m := m + 12;
y := y - 1;
end;
d := floor(365.25*y) + int(30.60001*(m+1)) + day - 723244.0;
if d < -145068.0 then
{julian calendar}
daynumber := d
else begin
{ convert to Gregorian calendar }
a := floor(y/100.0);
b := 2 - a + floor(a/4.0);
daynumber := d + b;
end
end;
procedure caldate(date:real; var year, month, day : integer);
{ inverse of daynumber; given date, finds year, month, and day. }
{ uses readl arithmetic becuase numbers are too big for integers }
var
a,aa,b,c,d,e,z: real;
y : integer;
begin
z := int(date + 2444239.0);
if date < -145078.0 then
{julian calendar}
a := z
else
{gregorian calendar}
begin
aa := floor((z - 1867216.25)/36524.25);
a := z + 1 + aa - floor(aa/4.0)
end;
b := (a + 1524.0);
c := int((b-122.1)/365.25);
d := int(365.25*c);
e := int((b-d)/30.6001);
day := trunc(b-d-int(30.6001*e));
if e > 13.5 then month := trunc(e - 13.0)
else month := trunc(e - 1.0);
if month > 2 then y := trunc(c - 4716.0)
else y := trunc(c - 4715.0);
if y < 1 then year := y - 1
else year := y
end;
function weekday(date:real):integer;
{ given day number as used in above routines, }
{ finds day of week (1 = Sunday, 2 = monday, etc). }
var
dd : real;
begin
dd := date;
while dd > 28000.0 do dd := dd - 28000.0;
weekday := ((trunc(dd) + 1) mod 7) + 1
end;